package edu.mobbuzz.daf.dao.ibatis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import edu.mobbuzz.daf.bean.BaseBean;
import edu.mobbuzz.daf.dao.IBaseDao;

public abstract class BaseDaoImpl extends SqlMapClientDaoSupport implements IBaseDao {
	protected abstract String getNamespace();
	
	public void insert(BaseBean bean) {
		try {
			getSqlMapClientTemplate().insert(getNamespace()+".insert",bean);
		}catch (Exception e) {
			e.printStackTrace();
			System.out.println("error ketika insert into "+ getNamespace());
		}	
	}
	
	public void update(BaseBean bean) {
		try {
			getSqlMapClientTemplate().update(getNamespace()+".update",bean);
		}catch (Exception e) {
			e.printStackTrace();
			System.out.println("error ketika update into "+ getNamespace());
		}	
		
	}
	
	public void delete(String id) {
		try {
			getSqlMapClientTemplate().delete(getNamespace()+".delete",id);
		}catch (Exception e) {
			e.printStackTrace();
			System.out.println("error ketika delete into "+ getNamespace());
		}	
		
	}

	

	public BaseBean findByPrimaryKey(String id) {
		try {
			return (BaseBean) getSqlMapClientTemplate().queryForObject(getNamespace()+".findByPrimaryKey", id);
		}catch (Exception e) {
			e.printStackTrace();
			System.out.println("error ketika findByPrimaryKey into "+ getNamespace());
		}	
		return null;
	}
	
	public BaseBean queryForBaseBean(String where) {
		try {
			Map map = new HashMap();
			map.put("where",where);
			return (BaseBean) getSqlMapClientTemplate().queryForObject(getNamespace()+".queryForBaseBean", map);
		}catch (Exception e) {
			e.printStackTrace();
			
		}	
		return null;
	}

	public List<BaseBean> queryForList(String where, String order) {
		try {
			Map map = new HashMap();
			map.put("where",where);
			map.put("order",order);
			List list = getSqlMapClientTemplate().queryForList(getNamespace()+".queryForList", map);
			return list;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
		
	}

	

}
